// pages/Visitor/showuser/showuser.js
var util = require('../../../utils/util.js');
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    dialog4: {
      hidden: true
    },
    updatetime: "",
    json: "",
    indate: "",
    state: "",
    title: "",
    str: ""
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var json = app.owner.json
    var jsonData = JSON.parse(json);

    this.setData({ json: jsonData });
    if (jsonData.yindate == 1) {
      this.setData({ indate: "审核通过" });
      this.setData({ title: "有效期" });
      this.setData({ str: "至" });
      this.setData({ updatetime: jsonData.yupdatetime.substring(0, 10) });
      this.setData({ state: jsonData.state.substring(0, 4) + "-" + jsonData.state.substring(5, 7) + "-" + jsonData.state.substring(6,8)});
    }else{
      this.setData({ indate: "审核中" });
      this.setData({ "0": jsonData.yupdatetime });
      this.setData({ "0": jsonData.state });
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  exit:function(){
    util.index("提示", "确定退出吗？");
  },
  update: function () {
    this.setData({ 'dialog4.hidden': false });
    var that = this;
    wx.request({
      method: "POST",
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      url: 'https://wwl.ycws.cc/ssm/visitors/openid',
      data: {
        openid: wx.getStorageSync('developer')
      },
      success: function (res) {
        console.log(res.data)
        var an = res.data;
        var json = JSON.stringify(an);
        app.owner.json = json;
        that.setData({ 'dialog4.hidden': true });
        wx.redirectTo({
          url: '../../../pages/Visitor/showuser/showuser'
        })
      }
    })
  },
  button: function (event) {
    if (event.currentTarget.id == "审核中") {
      util.msg("提示", "请前往管理处审核");
    }
  }
})